#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

void fun(vector<int> &vec, int i, int len)
{
    if(i == len){
        for(int v: vec){
            cout << v << " ";
        }
        cout << endl;
    }else{
        for(size_t j{i}; j < len; j++){

            int tmp = vec[i];
            vec[i] = vec[j];
            vec[j] = tmp;
            fun(vec, i + 1, len);

            vec[j] = vec[i];
            vec[i] = tmp;
        }
    }
}

int main(int args, char *argv[])
{
    vector<int> vec = {1, 2, 3, 4};
    fun(vec, 0, 4);
    return 0;
}